import WebServer from './Webserver.js';
import {serverPort} from './configuration.js';
import db from './mysqlHelper.js'

let web = new WebServer();
web.Start(serverPort);

let timer=setInterval(async ()=>{
    //将长时间没有通信的设备状态设置为离线
    let sql=`update device_real set is_online=0 where last_time < date_sub(now(),interval 2 minute)  and is_online=1`;
   let res = await db.query(sql);
  // console.log(res,JSON.stringify(res));
   if(res.affectedRows>0){
    sql=`UPDATE   device,device_real   set device.status=device_real.is_online  WHERE  device.sn=device_real.sn AND device.status!=device_real.is_online`;
    await db.excute(sql);
   // console.log("同步设备状态");
   }

   
},1000*60);